package com.cmict.data.bpm.dal.mysql.definition;

import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;
import java.util.Set;

@Mapper
public interface BpmProcessDefinitionExtMapper extends BaseMapperX<BpmProcessDefinitionExtDO> {

    default List<BpmProcessDefinitionExtDO> selectListByProcessDefinitionIds(Collection<String> processDefinitionIds) {
        return selectList("process_definition_id", processDefinitionIds);
    }

    default BpmProcessDefinitionExtDO selectByProcessDefinitionId(String processDefinitionId) {
        return selectOne("process_definition_id", processDefinitionId);
    }

    @Select({"SELECT process_definition_id,model_id FROM `bpm_process_definition_ext` WHERE form_id = #{formId} " +
            "and deleted = 0 and form_type = 20 ORDER BY create_time desc LIMIT 1 "})
    BpmProcessDefinitionExtDO selectByFormId(Long formId);

    @Select({"SELECT process_definition_id FROM `bpm_process_definition_ext` " +
            "WHERE model_id = (SELECT model_id FROM `bpm_process_definition_ext` WHERE form_id = #{formId} and deleted = 0 and form_type = 20 ORDER BY create_time desc LIMIT 1)" +
            "and form_id = #{formId}"})
    Set<String> getDefineIdsByFormId(Long formId);


    @Select({"SELECT process_definition_id,model_id FROM `bpm_process_definition_ext` WHERE form_id = #{formId} " +
            "and deleted = 0 and form_type = 20"})
    List<BpmProcessDefinitionExtDO> selectListByFormId(Long formId);
}
